<template>
  <div>
    <el-table :data="noneCompetitiveTableData" :span-method="objectSpanMethod" stripe size="mini" style="width: 100%">
      <el-table-column prop="locationName" label="比赛场地" :width="70" align="center" />
      <el-table-column prop="phaseName" label="进程" :width="80" align="center" />
      <el-table-column prop="unitCode" label="场次号" :width="100" align="center" />
      <el-table-column prop="eventName" label="比赛项目" :min-width="200" />
      <el-table-column prop="statusName" label="状态" :width="70" align="center" />
      <el-table-column label="参赛方" :width="200">
        <template slot-scope="{ row }">
          <PersonalImage v-if="row.registerTypeCode == 'I'" :imgurl="row.imagePath" :imgheight="'50px'" />
          <div v-else style="display:inline-block;">
            <img :src="getStaticFileUrl(row.imagePath)" class="person_img" @error="errorPhoto">
          </div>
          <div v-if="row.registerTypeCode == 'I'" class="gl_ml_10" style="display:inline-block; width: calc(100% - 60px); line-height: 22px; vertical-align: middle;">
            <el-popover placement="top" width="300" trigger="hover" :content="row.playerName">
              <div slot="reference" class="gl_ellipsis">{{ row.playerName ? row.playerName : '- -' }}</div>
            </el-popover>
            <el-popover placement="bottom" width="300" trigger="hover" :content="row.delegationName">
              <div slot="reference" class="gl_ellipsis">{{ row.delegationName ? row.delegationName : '- -' }}</div>
            </el-popover>
          </div>
          <div v-else class="gl_ml_10" style="display:inline-block; width: calc(100% - 60px); line-height: 22px; vertical-align: middle;">
            <el-popover placement="bottom" width="300" trigger="hover" :content="row.delegationName">
              <div slot="reference" class="gl_ellipsis">{{ row.delegationName ? row.delegationName : '- -' }}</div>
            </el-popover>
            <el-popover placement="bottom" width="300" trigger="hover" :content="row.memberNames">
              <div slot="reference" class="gl_ellipsis">{{ row.memberNames ? row.memberNames : '- -' }}</div>
            </el-popover>
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="totalScore" label="总得分" align="center" />
      <el-table-column prop="expressiveScore" label="表现力得分" align="center" />
      <el-table-column prop="accuracyScore" label="准确率得分" align="center" />
      <el-table-column prop="rank" label="比赛名次" :width="70" align="center" />
    </el-table>
  </div>
</template>
<script>
import { mapState, mapActions } from 'vuex';
import defaultPersonImg from '@/assets/images/face_default.png';
import PersonalImage from '@/components/PersonalImage/index';
export default {
  name: 'NoneCompetitive',
  components: {
    PersonalImage
  },
  props: {
    noneCompetitiveTableData: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      defaultPersonImg: defaultPersonImg
    };
  },
  computed: {
    ...mapState({
      dict: state => state.dict.dict
    })
  },
  created() {
    this.getDict();
  },
  methods: {
    ...mapActions({ getDict: 'dict/getDict' }),
    // 定义需要合并的表格列
    objectSpanMethod({ row, column, rowIndex, columnIndex }) {
      if (columnIndex < 5) {
        const _row = this.setTable(this.noneCompetitiveTableData).one[rowIndex];
        const _col = _row > 0 ? 1 : 0;
        return {
          rowspan: _row,
          colspan: _col
        };
      }
    },
    // 合并表格行
    setTable(tableData) {
      const spanArr = [];
      let concat = 0;
      tableData.forEach((item, index) => {
        if (index === 0) {
          spanArr.push(1);
        } else {
          if (item.unitId === tableData[index - 1].unitId) {
            // 需合并相同内容的判断条件
            spanArr[concat] += 1;
            spanArr.push(0);
          } else {
            spanArr.push(1);
            concat = index;
          }
        }
      });
      return {
        one: spanArr
      };
    },
    // 获取静态图片地址
    getStaticFileUrl(relativeUrl) {
      if (!relativeUrl) return '';
      return WEB_CONFIG.VUE_APP_STATIC_FILE_RUL + relativeUrl;
    },
    errorPhoto() {
      const img = event.srcElement;
      img.src = this.defaultPersonImg;
    }
  }
};
</script>
<style scoped>
.person_img {
  max-width: 50px;
  max-height: 50px;
  display: block;
}
</style>
